import { ref, computed } from 'vue'
import { defineStore } from 'pinia'

export const useCoreStore = defineStore('core', () => {
  const fields = ref([])
  const curField = ref(null)
  const drawer = ref(false)
  const curColumn = ref([])
  const subJsonList = ref([])
  // 添加字段的方法
  function addField(val) {
    fields.value.push(val)
  }

  // 设置当前字段的方法
  function setCurField(val) {
    curField.value = val
    drawer.value = true
    if (val.dicUrl) {
      val.dicName = val.dicUrl.split("=").pop()
    }
    console.log("curField", val)
  }

  // 设置当前列表
  function setCurColumn(val) {
    curColumn.value = val
  }

  // 设置当前字段的方法
  function setFields(val) {
    fields.value = val
    console.log("fields", fields)
  }

  function setDrawer(val) {
    drawer.value = val
  }

  function setSubJsonList(val) {
    subJsonList.value = val
  }

  function deleteField(val) {
    fields.value.splice(fields.value.indexOf(val), 1)
  }

  return { subJsonList, drawer, fields, curField, curColumn, setSubJsonList, setDrawer, addField, setCurField, setFields, deleteField, setCurColumn }
})
